<html>

<head>
    <meta charset="utf-8"/>
    <meta name="Author" content="hyjiacan,hyjiacan@163.com"/>
    <meta name="Keywords" content="ColorWanted,colorpicker,赏色,取色器,拾色器"/>
    <meta name="Description" content="Screen color picker for Windows, 好用的Windows屏幕取色器"/>
    <meta charset="UTF-8"/>
    <meta http-equiv="Pragma" content="no-cache"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>ColorWanted: Screen color picker for Windows/好用的Windows屏幕取色器 - 官方网站</title>
    <link rel="stylesheet" type="text/css" href="./css/default.css"/>
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/md0/dist/md0.css"/>
    <script src="https://cdn.bootcss.com/Base64/1.0.2/base64.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/md0/dist/md0.js" type="text/javascript"></script>
</head>

<body>
<div class="container">
    <div class="mask"></div>
    <div id="metas">
        <span class="latest-text"></span>
        <span class="loaded">
          <span>
              <a href="" id="source"></a>
          </span>
          <span class="release-text"></span>
          <span id="date"></span>
        </span>
        <span class="pending"></span>
    </div>
    <main id="content" class="markdown">
    </main>
    <footer>
      Markdown renderer powered by <a href="https://github.com/hyjiacan/md0" target="_blank">md0</a>
    </footer>

    <script type="text/javascript">
    var metas = document.querySelector('#metas')

    function readmeCallback(response) {
        var markdownText = decodeURIComponent(escape(atob(response.data.content.replace(/\n/g, ''))))
        render(markdownText.replace(/\r\n/g, '\n'))
    }
    
    function render(markdownText) {
        var html = md0(markdownText)
        html = html.replace(/docs\/img/g, 'img')
        var content = document.querySelector('#content');
        content.innerHTML = html.replace(/README\.(zh-CN\.)?md"/, 
          '#" onclick="window.location.search=\'?lang=' + (isZH ? 'en' : 'zh') + '\';return false;"')

        var title = content.querySelector('h1')
        title.appendChild(metas)
        
        document.body.classList.add('content-loaded')

        // 追加其它数据
        var handle = setInterval(function () {
            if (!window.latest) {
                return
            }
            clearInterval(handle)

            var source = document.querySelector('#source');
            source.href = latest.tag
            source.innerHTML = latest.version
        }, 100)
    }
    
    function jsonp(url, callback) {
      var script = document.createElement('script')
      script.setAttribute('src', url + '?callback=' + callback)
      script.setAttribute('type', 'text/javascript')
      document.head.appendChild(script)
    }
    
    function dateCallback(response) {
        var date = response.data.commit.author.date
        document.querySelector('#date').innerHTML = new Date(Date.parse(date)).toLocaleString()
        metas.classList.add('loaded')
    }

    function tagsCallback(response) {
        var tag = response.data[0]
        window.latest = {
            version: tag.name,
            tag: 'https://github.com/hyjiacan/ColorWanted/releases/tag/' + tag.name
        }

        // 加载日期
        jsonp(tag.commit.url, 'dateCallback')
    }

    var isZH = /^zh/i.test((/^.*?[?&]lang=(.+?)(&.*)?$/.exec(window.location.search) || [])[1] || navigator.language)
    var readmeFile = isZH ? 'README.zh-CN' : 'README'
    var readmeUrl = 'https://api.github.com/repos/hyjiacan/ColorWanted/contents/' + readmeFile + '.md'
    document.body.classList.add(isZH ? 'zh' : 'en')
    jsonp(readmeUrl, 'readmeCallback')
    </script>
    <script src="https://api.github.com/repos/hyjiacan/ColorWanted/tags?callback=tagsCallback" type="text/javascript"
            charset="utf-8"></script>
</div>
</body>

</html>